public class SelectionManager {

    private static volatile SelectionManager mSelectionManager;
    private Set<String> mSelectImagePaths = new HashSet<>();
    private int maxChoose = 9;

    public static SelectionManager getInstance() {
        if (mSelectionManager == null) { 
            synchronized (SelectionManager.class) {
                if (mSelectionManager == null) {
                    mSelectionManager = new SelectionManager();
                }
            }
        }
        return mSelectionManager;
    }


    //最大选择数
    public void setMaxChoose(int maxChoose) {
        this.maxChoose = maxChoose;
    }

    //获取最大选择数
    public int getMaxChoose() {
        return this.maxChoose;
    }

    //获取当前所选图片集合path
    public Set<String> getSelectPaths() {
        return mSelectImagePaths;
    }

    //添加/移除图片到选择集合
    public boolean addImageToSelectList(String imagePath) {
        if (mSelectImagePaths.contains(imagePath)) {
            return mSelectImagePaths.remove(imagePath);
        } else {
            if (mSelectImagePaths.size() < mMaxChoose) {
                return mSelectImagePaths.add(imagePath);
            } else {
                return false;
            }
        }
    }

    //添加图片到选择集合
    public void addImagePathsToSelectList(List<String> imagePaths) {
        if (imagePaths != null) {
            removeAll();
            for (int i = 0; i < imagePaths.size(); i++) {
                String imagePath = imagePaths.get(i);
                if (!mSelectImagePaths.contains(imagePath) && mSelectImagePaths.size() < mMaxCount) {
                    mSelectImagePaths.add(imagePath);
                }
            }
        }
    }

    //判断当前图片是否被选择
    public boolean isImageSelect(String imagePath) {
        if (mSelectImagePaths.contains(imagePath)) {
            return true;
        } else {
            return false;
        }
    }

    //清除已选图片
    public void removeAll() {
        mSelectImagePaths.clear();
    }

}
